#include "exti.hpp"
bool led_status_is_enabled = 0;
GPIO_InitTypeDef EXTI_settings::GPIO_initstruct;
EXTI_InitTypeDef EXTI_settings::EXTI_initstruct;
NVIC_InitTypeDef EXTI_settings::NVIC_InitStruct;
void EXTI_settings::set_exti()
{
    Set_exti_GPIOs();

    Set_exti_mode();
    set_exti_nvic();
}
void EXTI_settings::Set_exti_GPIOs()
{
    GPIO_initstruct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_13;
    GPIO_initstruct.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIOA, &GPIO_initstruct);
    // GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET);
}
void EXTI_settings::Set_exti_mode()
{
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource2);
    EXTI_initstruct.EXTI_Line = EXTI_Line2 | EXTI_Line6 | EXTI_Line7 | EXTI_Line13;
    EXTI_initstruct.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_initstruct.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_initstruct.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_initstruct);
    // GPIO_WriteBit(GPIOB, GPIO_Pin_4, Bit_RESET);
}
void EXTI_settings::set_exti_nvic()
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStruct);
    // GPIO_WriteBit(GPIOB, GPIO_Pin_6, Bit_RESET);
    NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2;
    NVIC_Init(&NVIC_InitStruct);
    NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 3;
    NVIC_Init(&NVIC_InitStruct);
}
